<?php
require_once 'base_model.php';

class Therapist_model extends Base_model {
	private static $fields = array(
		"name", "blood_type", "birth_date", "birth_place", "height",
		"comment", "salon_comment", "image_path",
		"new_member", "hired_date",
	);
	var $name;
	var $blood_type;
	var $birth_date;
	var $birth_place;
	var $height;
	var $comment;
	var $salon_comment;
	var $image_path;
	var $new_member;
	var $hired_date;

	function __construct() {
		parent::__construct('therapists');
		$this->birth_date = "1990-01-01";
		$this->new_member = TRUE;
	}

	function select_all($limit = 0, $offset = 0, $order_by_modified_date = TRUE) {
		$this->db->where('del', 0);
		if ($order_by_modified_date) $this->db->order_by('modified_date', 'desc');
		$query = $this->db->get('therapists');
		return $query->result();
	}
	protected function get_field_names() {
		return array_merge(parent::get_field_names(), Therapist_model::$fields);
	}
	function load_from_post($update_create_date = FALSE, $update_modified_date = FALSE) {
		parent::load_from_post($update_create_date, $update_modified_date);
		if (!isset($this->new_member)) $this->new_member = FALSE;
		$year = $this->input->post('birth_year');
		$month = $this->input->post('birth_month');
		$date = $this->input->post('birth_day_of_month');
		$this->birth_date = ($year > 0 && $month > 0 && $date > 0) ? sprintf("%04d-%02d-%02d", $year, $month, $date) : null;
	}
}
